<?php

/* @var $this \yii\web\View */
/* @var $content string */

use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use app\assets\AppAsset;
use app\modules\backend\rbac\components\MenuHelper;

AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>

<div class="wrap">
    <?php
    NavBar::begin([
        'brandLabel' => '智慧农业云平台',
        //'brandUrl' => Yii::$app->homeUrl,
        'brandUrl' => ['/backend/site/index'],
        'options' => [
            'class' => 'navbar-inverse navbar-fixed-top',
        ],
    ]);
    // 以下为基于RBAC的菜单管理
$menuItems = array();
foreach (MenuHelper::getAssignedMenu(\Yii::$app->user->id) as $k => $p_menu) {

    if (!empty($p_menu['items'])) {
        //多级菜单设置，未完成
        foreach ($p_menu['items'] as $val) {
            if ($val['url'][0]) {
            }
        }

        foreach ($p_menu['items'] as $c_menu) {
        }
    } else {
        //单级菜单
        if($p_menu['label']==("管理本公司")){
            $label=Yii::$app->user->identity->person->company->name;
            $url=$p_menu['url'][0];
        $menuItems[]=['label' =>$label, 'url' => [$url,'id'=>1]];
        }else{
            $menuItems[]=['label' =>$p_menu['label'], 'url' => [$p_menu['url'][0]]];
        }
    }
}
    //以上为基于RBAC的菜单管理 -->
//    $menuItems = array();
//    $menuItems=[
//            ['label'=>'权限管理','url'=>['/backend/rbac']],
//            ['label'=>'公司管理','url'=>['/backend/company/index']],
//            ['label'=>'园区管理','url'=>['/backend/park/index']],
//            ['label'=>'地块管理','url'=>['/backend/land/index']],
//            ['label'=>'设备管理','url'=>['/backend/equip/index']],
//            ['label'=>'设备类型管理','url'=>['/backend/equiptype/index']],
//            ['label'=>'作物类型管理','url'=>['/backend/croptype/index']],
//            ['label'=>'人员管理','url'=>['/backend/person/index']],
//    ];



    if(Yii::$app->user->isGuest){
        $menuItems[] = ['label' => '注册', 'url' => ['/backend/site/signup']];
        $menuItems[] = ['label' => '登入', 'url' => ['/site/login']];
    }else {
        $menuItems[] =  ['label'=>Yii::$app->user->identity->username,'items'=>[
            ['label'=>'用户信息', 'url' => ['/backend/site/user']],
            ['label' => '注销', 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']],

        ]];
    }

    echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-right'],
        'items' => $menuItems
    ]);

    NavBar::end();
    ?>

    <div class="container">
        <?= Breadcrumbs::widget([
            'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
        ]) ?>
        <?= $content ?>
    </div>
</div>

<footer class="footer">
    <div class="container">
        <p class="pull-left">&copy; My Company <?= date('Y') ?></p>

        <p class="pull-right"><?= Yii::powered() ?></p>
    </div>
</footer>

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
